﻿@model cloudscribe.Web.Common.Models.FormItemDefinition
@inject IStringLocalizer<CloudscribeCommonResources> sr
@{
    var grpClass = "";// input-group
    var spnClass = ""; //input-group-addon
    if (!string.IsNullOrWhiteSpace(Model.IconCssClass))
    {
        grpClass = "input-group";
        spnClass = "input-group-text";

    }
    if (ViewData[Model.Key] != null)
    {
        var currentVal = ViewData[Model.Key].ToString();
        foreach (var o in Model.Options)
        {
            if (o.Value == currentVal)
            {
                o.Selected = true;
            }
            else
            {
                o.Selected = false;
            }
        }

    }
}
<div class="form-group">
    <label for="@Model.Key">@sr[Model.Label]</label>
    <div class="@grpClass">
        @if (!string.IsNullOrWhiteSpace(Model.IconCssClass) && Model.IconOnLeft)
        {
            <div class="input-group-prepend">
                <span class="@spnClass"><i class="@Model.IconCssClass" aria-hidden="true"></i></span>
            </div>
        }
        <select name="@Model.Key" asp-items="Model.Options" title="@Model.Tooltip" class="form-control" cs-form-item-definition="@Model"></select>
        @if (!string.IsNullOrWhiteSpace(Model.IconCssClass) && !Model.IconOnLeft)
        {
            <div class="input-group-append">
                <span class="@spnClass"><i class="@Model.IconCssClass" aria-hidden="true"></i></span>
            </div>
        }
    </div>
    <span class="text-danger field-validation-valid" data-valmsg-for="@Model.Key" data-valmsg-replace="true"></span>
    @Html.ValidationMessage(Model.Key + "Error", new { @class = "text-danger" })
</div>
